import { createRouter, createWebHashHistory } from "vue-router";
import HomeView from "../views/home/index.vue"
const routes = [
    {
        path: '/',
        name: 'home',
        component: HomeView
    },
    {
        path: '/lecture',
        name: 'lecture',
        component: () => import('../views/lecture/index.vue'),
    },
    {
        path: '/my',
        name: 'my',
        component: () => import('../views/my/index.vue'),
        // 路由守卫
        beforeEnter: (to:any, from:any, next:any) => {
            const token = window.localStorage.getItem('token');
            if (!token) {
              next('/login'); // 如果没有 token，重定向到登录页面
            } else {
              next(); // 如果有 token，正常跳转
            }
          }
    },
    {
        path: "/login",
        name: "login",
        meta: {
            hidden: true,
        },
        component: () => import("../views/login/index.vue")
    },
    {
        path: "/register",
        name: "register",
        meta: {
            hidden: true,
        },
        component: () => import("../views/register/index.vue"),
    },
    {
        path: '/achievement',
        name: 'achievement',
        meta: {
            hidden: true,
        },
        component: () => import("../views/achievement/index.vue"),
    },
    {
        path: '/jiangzuo',
        name: 'jiangzuo',
        meta: {
            hidden: true,
        },
        component: () => import("../views/lecture/jiangzuo.vue"),
    },
    {
        path: '/achieve1',
        name: 'achieve1',
        meta: {
            hidden: true,
        },
        component: () => import("../views/achievement/achieve1.vue"),
    },
    // 收货地址
    {
        path: '/my/location',
        name: 'location',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/location/index.vue'),
    },
    // 上传日志
    {
        path: '/my/upload',
        name: 'upload',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/upload/index.vue'),
    },
    // 帮助中心
    {
        path: '/my/help',
        name: 'help',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/help/index.vue'),
    },
    // 投诉举报
    {
        path: '/my/complaint',
        name: 'complaint',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/complaint/index.vue'),
    },
    // 评定学生账号
    {
        path: '/my/evaluate',
        name: 'evaluate',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/evaluate/index.vue'),
    },
    // 意见反馈
    {
        path: '/my/opinion',
        name: 'opinion',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/opinion/index.vue'),
    },
    // 我的讲座
    {
        path: '/my/chair',
        name: 'chair',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/chair/index.vue'),
    },
    // 学习计划
    {
        path: '/my/plan',
        name: 'plan',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/plan/index.vue'),
    },
    // 代金券
    {
        path: '/my/voucher',
        name: 'voucher',
        meta: {
            hidden: true
        },
        component: () => import('../views/my/voucher/index.vue'),
    },
    {
        path: '/wrongbook',
        name: 'wrongbook',
        meta: {
            hidden: true,
        },
        component: () => import("../views/wrongbook/index.vue"),
    },
    {
        path: '/wrxiangq',
        name: 'wrxiangq',
        meta: {
            hidden: true,
        },
        component: () => import("../views/wrxiangq/index.vue"),
    },
    {
        path: '/analysis',
        name: 'analysis',
        meta: {
            hidden: true
        },
        component: () => import("../views/analysis/index.vue")
    }
]
const router = createRouter({
    history: createWebHashHistory(import.meta.env.BASE_URL),
    routes,
});
export default router
